home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************
- * Generated by OEGen.
- * Comments....... This file contains the Database Mgmt. code specific to
- * the descendents of a persistant class. This code is
- * generated automatically.
- *
- ***************************************************************************/
-
- #include "C:\FITDEV\DATABASE\TEST.HPP"
- #ifdef _Windows
- ObjEng objeng("OEApp");
- #else
- ObjEng objeng;
- #endif
-
-
- //------------------------------------------------------------
- // The Client Class Constructor
- //------------------------------------------------------------
- Client::Client() : PersistClass("client")
- {
- id = 0;
- strcpy(fname, "");
- tests = new OEList;
- strcpy(localtypes, "LA^L");
-
- if (!objeng.IsRegistered(oehandle))
- {
- char *FieldNames[] = {"ID", "FNAME", "TESTS", "ObjectID"};
- char *FieldTypes[] = {"N", "A12", "N", "N"};
- int nFields = 4;
- FIELDHANDLE IdxFlds[] = { 1 };
- int nIdxFields = 1;
- if ((status = objeng.Register(oehandle, FieldNames, FieldTypes, IdxFlds, nFields, nIdxFields)) != PXSUCCESS) return;
- }
- // ANY ADDITIONAL CONSTRUCTOR CODE CAN BE PLACED HERE...
- }
-
-
-
- //------------------------------------------------------------
- // Copy contents from one client to another - DO NOT link them.
- // (objectID is not copied so the copy doesn't refer to DB record).
- //------------------------------------------------------------
- Client &Client::operator=(const Client &val)
- {
- id = val.id;
- strcpy(fname, val.fname);
- tests = val.tests;
- if (tests != NULL)
- tests->AddReference(); //Increment refcount to avoid unwanted deletion
- strcpy(localtypes, "LA^L");
-
- // Base class copies...
- Copy((PersistClass &)val);
- return *this;
- }
-
-
- //------------------------------------------------------------
- // Link to the record matching on the given number of index fields.
- //------------------------------------------------------------
- int Client::LinkToKey(int nIdxFields, int mode)
- {
- //Copy all of the Primary index fields to the recbuf
- PXPutLong(oehandle.rHdl, 1, id);
- // Do the SrchKey on just those that are asked for (nIdxFields).
- if ((status = PXSrchKey(oehandle.tHdl, oehandle.rHdl, nIdxFields, mode)) == PXSUCCESS)
- return Retrieve();
- else
- return status;
- }
-
-
- //------------------------------------------------------------
- // Store a filled/changed object - create an indexID if virgin,
- // otherwise, store under the objectID.
- //------------------------------------------------------------
- int Client::Store()
- {
- PXPutLong(oehandle.rHdl, 1, id);
- PXPutAlpha(oehandle.rHdl, 2, fname);
- long listid0 = tests->GetListID();
- PXPutLong(oehandle.rHdl, 3, listid0);
- if (objectID == 0) // Not yet added, give Index, then add
- {
- if ((status = objeng.GetIndex(objectID, 0)) != PXSUCCESS) return status;
- PXPutLong(oehandle.rHdl, 4, objectID);
- status = PXRecInsert(oehandle.tHdl, oehandle.rHdl);
- }
- else // 'Tis an update.
- {
- PXPutLong(oehandle.rHdl, 4, objectID);
- status = PXSrchFld(oehandle.tHdl, oehandle.rHdl, 4, SEARCHFIRST);
-
- if (status == PXSUCCESS)
- status = PXRecUpdate(oehandle.tHdl, oehandle.rHdl);
- else
- {
- // If you want a missing object to be an error, then
- // uncomment THIS line....
- // status = PXERR_RECNOTFOUND;
- // and comment out THIS line....
- status = PXRecInsert(oehandle.tHdl, oehandle.rHdl);
- }
- }
- return status;
- }
-
- //------------------------------------------------------------
- // An Object Retrieve Function - Private! Should only be called by
- // one of the linking functions (Link..., First, Last, ++, --)
- //------------------------------------------------------------
- int Client::Retrieve()
- {
- // Free up memory currently allocated to OEList if OEList
- // reference count is 0.
- if ((tests != NULL) && (tests->DeleteOK() == TRUE)) delete tests;
- if ((status = PXRecGet(oehandle.tHdl, oehandle.rHdl)) == PXSUCCESS)
- {
- PXGetLong(oehandle.rHdl, 1, &id);
- PXGetAlpha(oehandle.rHdl, 2, 13, fname);
- long listid0;
- PXGetLong(oehandle.rHdl, 3, &listid0);
- tests = new OEList(listid0);
- PXGetLong(oehandle.rHdl, 4, &objectID);
- }
- return status;
- }
-
-
- //------------------------------------------------------------
- // The Test Class Constructor
- //------------------------------------------------------------
- Test::Test() : PersistClass("test")
- {
- id = 0;
- uid = 0;
- weight = 0.0;
- score = 0;
- date.tm_mday = 0;
- date.tm_mon = 0;
- date.tm_year = 0;
- height = 0.0;
- strcpy(localtypes, "LL$SD$L");
-
- if (!objeng.IsRegistered(oehandle))
- {
- char *FieldNames[] = {"ID", "UID", "WEIGHT", "SCORE", "DATE", "HEIGHT", "ObjectID"};
- char *FieldTypes[] = {"N", "N", "$", "S", "D", "$", "N"};
- int nFields = 7;
- FIELDHANDLE IdxFlds[] = { 1, 2 };
- int nIdxFields = 2;
- if ((status = objeng.Register(oehandle, FieldNames, FieldTypes, IdxFlds, nFields, nIdxFields)) != PXSUCCESS) return;
- }
- // ANY ADDITIONAL CONSTRUCTOR CODE CAN BE PLACED HERE...
- }
-
-
-
- //------------------------------------------------------------
- // Copy contents from one client to another - DO NOT link them.
- // (objectID is not copied so the copy doesn't refer to DB record).
- //------------------------------------------------------------
- Test &Test::operator=(const Test &val)
- {
- id = val.id;
- uid = val.uid;
- weight = val.weight;
- score = val.score;
- date.tm_mday = val.date.tm_mday;
- date.tm_mon = val.date.tm_mon;
- date.tm_year = val.date.tm_year;
- height = val.height;
- strcpy(localtypes, "LL$SD$L");
-
- // Base class copies...
- Copy((PersistClass &)val);
- return *this;
- }
-
-
- //------------------------------------------------------------
- // Link to the record matching on the given number of index fields.
- //------------------------------------------------------------
- int Test::LinkToKey(int nIdxFields, int mode)
- {
- //Copy all of the Primary index fields to the recbuf
- PXPutLong(oehandle.rHdl, 1, id);
- PXPutLong(oehandle.rHdl, 2, uid);
- // Do the SrchKey on just those that are asked for (nIdxFields).
- if ((status = PXSrchKey(oehandle.tHdl, oehandle.rHdl, nIdxFields, mode)) == PXSUCCESS)
- return Retrieve();
- else
- return status;
- }
-
-
- //------------------------------------------------------------
- // Store a filled/changed object - create an indexID if virgin,
- // otherwise, store under the objectID.
- //------------------------------------------------------------
- int Test::Store()
- {
- PXPutLong(oehandle.rHdl, 1, id);
- PXPutLong(oehandle.rHdl, 2, uid);
- PXPutDoub(oehandle.rHdl, 3, weight);
- PXPutShort(oehandle.rHdl, 4, score);
- OEPutDate(5, date);
- PXPutDoub(oehandle.rHdl, 6, height);
- if (objectID == 0) // Not yet added, give Index, then add
- {
- if ((status = objeng.GetIndex(objectID, 0)) != PXSUCCESS) return status;
- PXPutLong(oehandle.rHdl, 7, objectID);
- status = PXRecInsert(oehandle.tHdl, oehandle.rHdl);
- }
- else // 'Tis an update.
- {
- PXPutLong(oehandle.rHdl, 7, objectID);
- status = PXSrchFld(oehandle.tHdl, oehandle.rHdl, 7, SEARCHFIRST);
-
- if (status == PXSUCCESS)
- status = PXRecUpdate(oehandle.tHdl, oehandle.rHdl);
- else
- {
- // If you want a missing object to be an error, then
- // uncomment THIS line....
- // status = PXERR_RECNOTFOUND;
- // and comment out THIS line....
- status = PXRecInsert(oehandle.tHdl, oehandle.rHdl);
- }
- }
- return status;
- }
-
- //------------------------------------------------------------
- // An Object Retrieve Function - Private! Should only be called by
- // one of the linking functions (Link..., First, Last, ++, --)
- //------------------------------------------------------------
- int Test::Retrieve()
- {
- // Free up memory currently allocated to OEList if OEList
- // reference count is 0.
- if ((status = PXRecGet(oehandle.tHdl, oehandle.rHdl)) == PXSUCCESS)
- {
- PXGetLong(oehandle.rHdl, 1, &id);
- PXGetLong(oehandle.rHdl, 2, &uid);
- double temp1;
- PXGetDoub(oehandle.rHdl, 3, (double *)&temp1);
- weight = temp1;
- PXGetShort(oehandle.rHdl, 4, &score);
- OEGetDate(5, date);
- double temp2;
- PXGetDoub(oehandle.rHdl, 6, (double *)&temp2);
- height = temp2;
- PXGetLong(oehandle.rHdl, 7, &objectID);
- }
- return status;
- }
-
-
- //--------------------------------------------------------------------
- // This "global" function provides the mapping from table names
- // to table objects for the automatic "has-a" link storage/retrieval.
- // It is always generated last since it needs to summarize all of the
- // classes defined above.
- //--------------------------------------------------------------------
- PersistClass *GetPersistClass(char *tbl, const long &inID)
- {
- PersistClass* tmp;
-
- if (strcmp(tbl, "client") == 0)
- {
- Client *client = new Client();
- tmp = (PersistClass *)client;
- }
- else
- if (strcmp(tbl, "test") == 0)
- {
- Test *test = new Test();
- tmp = (PersistClass *)test;
- }
- else
- return NULL;
-
- // Common calls for all Persistant Classes.
- if ((tmp->GetStatus() != PXSUCCESS) || (tmp->LinkToID(inID) != PXSUCCESS))
- {
- delete tmp;
- return NULL;
- }
- return(tmp);
- }
-